#include "stdafx.h"
#include "wf_modifyscale.h"

#include "pf_snapper.h"



WF_ModifyScale::WF_ModifyScale(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_PreviewActionInterface("Scale Entities",
                           container, graphicView) {}


QAction* WF_ModifyScale::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// "Scale"
    QAction* action = new QAction(tr("&Scale"),  NULL);
	action->setIcon(QIcon(":/extui/modifyscale.png"));
    //action->zetStatusTip(tr("Scale Entities"));
    return action;
}

void WF_ModifyScale::init(int status) {
    PF_ActionInterface::init(status);

}



void WF_ModifyScale::trigger() {

    PF_DEBUG->print("PF_ActionModifyScale::trigger()");

    PF_Modification m(*container, graphicView);
    m.scale(data);

    PF_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
}



void WF_ModifyScale::mouseMoveEvent(PF_MouseEvent* e) {
    PF_DEBUG->print("PF_ActionModifyScale::mouseMoveEvent begin");

    if (getStatus()==SetReferencePoint) {

        PF_Vector mouse = snapPoint(e);
        switch (getStatus()) {
        case SetReferencePoint:
            referencePoint = mouse;
            break;

        default:
            break;
        }
    }

    PF_DEBUG->print("PF_ActionModifyScale::mouseMoveEvent end");
}



void WF_ModifyScale::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::LeftButton) {
        PF_Vector mouse = snapPoint(e);

        switch (getStatus()) {
        case SetReferencePoint:
            setStatus(ShowDialog);
            if (PF_DIALOGFACTORY->requestScaleDialog(data)) {
                data.referencePoint = referencePoint;
                trigger();
                finish();
            }
            break;

        default:
            break;
        }
    } else if (e->button()==Qt::RightButton) {
        deletePreview();
        init(getStatus()-1);
    }
}



void WF_ModifyScale::updateMouseButtonHints() {
    switch (getStatus()) {
        /*case Select:
            PF_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to scale"),
                                           tr("Cancel"));
            break;*/
    case SetReferencePoint:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"),
                                            tr("Cancel"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_ModifyScale::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::CadCursor);
}



void WF_ModifyScale::updateToolBar() {
    switch (getStatus()) {
        /*case Select:
            PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSelect);
            break;*/
    case SetReferencePoint:
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
        break;
    default:
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarModify);
        break;
    }
}


// EOF
